package com.gewu.pm.ui.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.gewu.pm.R;
import com.gewu.pm.app.AppAdapter;
import com.gewu.pm.bean.ReportItemBean;

/**
 * 报表项适配器
 */
public final class ReportItemAdapter extends AppAdapter<ReportItemBean> {

    public ReportItemAdapter(Context context) {
        super(context);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ReportHolder();
    }

    private final class ReportHolder extends AppAdapter<?>.ViewHolder {

        private final TextView tvReportName;
        private final TextView tvReportDesc;
        private final ImageView ivReportIcon;

        private ReportHolder() {
            super(R.layout.report_item);
            tvReportName = findViewById(R.id.tv_report_name);
            tvReportDesc = findViewById(R.id.tv_report_desc);
            ivReportIcon = findViewById(R.id.iv_report_icon);
        }

        @Override
        public void onBindView(int position) {
            ReportItemBean item = getItem(position);
            tvReportName.setText(item.getName());
            tvReportDesc.setText(item.getDescription());
            ivReportIcon.setImageResource(item.getIconRes());
        }
    }
}

